/*
 * error_handling.c
 *
 *  Created on: Dec 10, 2010
 *      Author: cpy.prefers.you@gmail.com
 */

#include "headers.h"

int Error(char *MessageFormat, ...)
{
    va_list arg_ptr;
    va_start(arg_ptr, MessageFormat);
    char *ErrorMessage = malloc(MESSAGE_LEN);
    vsprintf(ErrorMessage, MessageFormat, arg_ptr);
    printf("error: %s\n", ErrorMessage);
    return 0;
}

int Warning(char *MessageFormat, ...)
{
    va_list arg_ptr;
    va_start(arg_ptr, MessageFormat);
    char *WarningMessage = malloc(MESSAGE_LEN);
    vsprintf(WarningMessage, MessageFormat, arg_ptr);
    printf("warning: %s\n", WarningMessage);
    return 0;
}

int Abort(char *MessageFormat, ...)
{
    va_list arg_ptr;
    va_start(arg_ptr, MessageFormat);
    char *AbortMessage = malloc(MESSAGE_LEN);
    vsprintf(AbortMessage, MessageFormat, arg_ptr);
    Error(AbortMessage);
    exit(0);
}

int Expected(char *MessageFormat, ...)
{
    va_list arg_ptr;
    va_start(arg_ptr, MessageFormat);
    char *ExpectedMessage = malloc(MESSAGE_LEN);
    vsprintf(ExpectedMessage, MessageFormat, arg_ptr);
    strcat(ExpectedMessage, " expected");
    Abort(ExpectedMessage);
    return 0;
}
